# __author__ = 'zhenjiao.su'
# -*- coding: utf-8 -*-
from selenium.webdriver.support.ui import WebDriverWait
from Newwebdriver import Active
class shouye(Active):
    def __init__(self,driver):  #初始化配置
      Active.__init__(self,driver)
      from excelrw import readxls
      self.driver=driver
      self.b2cread=readxls("D:/pywebdriver/Pythonwebdriver/abc.xls")
      self.elread=readxls("D:/pywebdriver/Pythonwebdriver/element.xls")
      self.wgocity=(self.elread(1,1),self.elread(1,2))   #往返出发
      self.wbackcity=(self.elread(2,1),self.elread(2,2))  #往返返程
      self.choosetwogo=(self.elread(16,1),self.elread(16,2))   #往返选择按钮
      self.choseonego=(self.elread(17,1),self.elread(17,2))    #单程选择按钮
      self.adultlist=(self.elread(3,1),self.elread(3,2)) #成人选择按钮
      self.adultchooselist=(self.elread(4,1),self.elread(4,2))   #成人下拉选择
      self.childlist=(self.elread(5,1),self.elread(5,2))   #儿童选择信息
      self.childchooselist=(self.elread(6,1),self.elread(6,2))
      self.submit=(self.elread(7,1),self.elread(7,2))  #开始定制按钮
      self.dgocity=(self.elread(10,1),self.elread(10,2))
      self.dbackcity=(self.elread(11,1),self.elread(11,2))    #单程输入相关信息
      self.hotelcity=(self.elread(13,1),self.elread(13,2))
    def shouyeexit(self):  #判断是否进入首页
        try:
            WebDriverWait(self.find_element(self.wgocity),10).until(lambda a:a)
            return True
        except:
            return False
    def b2ccitypeople(self,changedate=None,choose=1):  #信息输入
        #从excel中取数据
        self.b2cpeople=self.b2cread(1,2)
        self.b2cchild=self.b2cread(1,3)
        if choose==1:   #往返
            self.b2cqcity=self.b2cread(1,0)
            self.b2chcity=self.b2cread(1,1)
            godatejs=str(self.b2cread(1,14))
            backdatejs=str(self.b2cread(1,15))
            self.find_element(self.choosetwogo).click()
            #城市输入
            self.find_element(self.wgocity).clear()
            self.find_element(self.wgocity).send_keys(self.b2cqcity)
            self.find_element(self.wbackcity).send_keys(self.b2chcity)
            #出发与回程日期输入
            if changedate !=None:
                godatejs=("document.getElementById(\"js_fromdate\").value=\"%s\""%godatejs)
                batedatejs=("document.getElementById(\"js_todate\").value=\"%s\""%backdatejs)
                self.driver.execute_script(godatejs)
                self.driver.execute_script(batedatejs)
        elif choose==2:   #单程
            self.find_element(self.choseonego).click()
            self.find_element(self.dgocity).clear()
            self.find_element(self.dgocity).send_keys(u"北京")
            self.find_element(self.dbackcity).send_keys(u"上海")
            self.find_element(self.hotelcity).send_keys(u"北京")
        #人数输入
        self.find_element(self.adultlist).click()
        peoples1=self.find_elements(self.adultchooselist)
        peoples1[int(self.b2cpeople)].click()
        self.find_element(self.childlist).click()
        peoples2=self.find_elements(self.childchooselist)
        peoples2[int(self.b2cchild)].click()
    def b2cclick(self): #请求点击
        self.find_element(self.submit).click()






